package io.gitee.chearnee.fw.socket.component;

import io.gitee.chearnee.fw.socket.entity.MsgEntity;
import io.gitee.chearnee.fw.socket.handler.BaseBizHandler;
import io.netty.channel.ChannelHandlerContext;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class NettyDispatcher {

    private static final NettyDispatcher instance = new NettyDispatcher();
    private NettyDispatcher() {
    }
    public static NettyDispatcher getInstance() {
        return instance;
    }

    private static final Map<String, Object> bizmaps = new ConcurrentHashMap<>();

    public void msgReceived(ChannelHandlerContext channelHandlerContext, MsgEntity msgEntity) {
        BaseBizHandler baseBusinessCourse = (BaseBizHandler) bizmaps.get(msgEntity.getMsgCode());
        baseBusinessCourse.doBiz(channelHandlerContext, msgEntity);
    }

    public void setBizMaps(Map<String, Object> courseMap) {
        if (courseMap != null && courseMap.size() > 0) {
            for (Map.Entry<String, Object> entry : courseMap.entrySet()) {
                bizmaps.put(entry.getKey(), entry.getValue());
            }
        }
    }

}
